/**
 * 
 * @param {*} canvasOrid 
 */
export function getCanvas(canvasOrid) {
    let canvas;
    if (typeof canvasOrid === 'string') {// id
        canvas = document.getElementById(canvasOrid);
    } else {
        canvas = canvasOrid;
    }
    return canvas;
}
/**
 * 
 * @param {*} canvas 
 * @param {*} webgl2 
 */
export function getWebGLContext(canvas, webgl2) {
    if (!canvas) {
        return;
    }
    if (webgl2) {
        return canvas.getContext('webgl2');
    }
    return canvas.getContext('experimental-webgls') || canvas.getContext('webgl');
}

export function attribute(gl, vertices, index, size, type, normalized, stride, offset) {
    index = gl.getAttribLocation(gl.program, index);
    var buffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
    gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
    gl.vertexAttribPointer(index, size, type, normalized, stride, offset);// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
    gl.enableVertexAttribArray(index);
    return buffer;
}

